package com.sky.controller.admin;


import cn.hutool.core.convert.Convert;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @GetMapping("/page")
    public Result<PageResult> findPage(SetmealPageQueryDTO pageQuery){
        PageResult pageResult=setmealService.findPage(pageQuery);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result insertService(@RequestBody SetmealDTO setmealDTO){
        setmealService.insertService(setmealDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result updateStatus(@RequestBody @PathVariable("status")Integer status,long id){
        setmealService.updateStatus(status,id);
        return Result.success();
    }

    @DeleteMapping
    public Result deleteByIds(Integer[] ids){
        List<Integer> list = Convert.toList(Integer.class, ids);
        //List<Integer> ids1 = List.of(ids);
        setmealService.deleteByIds(list);
        return Result.success();
    }

    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }
    @GetMapping("{id}")
    public Result<SetmealVO> findById(@PathVariable("id")Long id){
        SetmealVO setmealVO=setmealService.findById(id);
        return Result.success(setmealVO);
    }
}
